package com.college.common.utils.page;

import com.alibaba.fastjson2.JSONObject;
import com.college.common.pojo.model.page.PageParamRequest;

import java.util.List;
import java.util.stream.Collectors;

public class PageUtils {
    /**
     * 手动分页
     * */
    public static <T> JSONObject page(PageParamRequest paramRequest, List<T> list){
        JSONObject response = new JSONObject();
        response.put("page",paramRequest.getPage());
        response.put("limit",paramRequest.getLimit());
        response.put("list",list.stream().skip((paramRequest.getPage()-1)*paramRequest.getLimit()).limit(paramRequest.getLimit()).collect(Collectors.toList()));
        response.put("total",list.size());
        response.put("totalPage",list.size()/ paramRequest.getLimit()+1);
        return response;
    }
}

